{% extends "base.html" %}

{% block title %}
Agenda - {{local.nome}}
{% endblock title %}

{% block extrahead %}
{% load extra_datetime %}
	var year = new Date().getFullYear();
	var month = new Date().getMonth();
	var day = new Date().getDate();
   
	var eventData = {
		events : [
		{% for aula in lista_aulas %}
		   {"id":{{aula.id}}, "start": new Date( {{aula.inicio.year}} , {{aula.inicio.month}}-1 , {{aula.inicio.day}} ,  {{aula.inicio.hour}}, {{aula.inicio.minute}}), "end": new Date( {{aula.fim.year}} , {{aula.fim.month}}-1 , {{aula.fim.day}} ,   {{aula.fim.hour}}, {{aula.fim.minute}}),"title":"Professor(a): {{aula.professor.detalheusuario.nome}} - Alunos:{% for aluno in aula.aluno.all %}{{aluno.nome}};{% endfor %} "},
		{% endfor %}
		]
	};


	   
	$(document).ready(function() {
		$('#calendar').weekCalendar({
			timeslotsPerHour: 4,
			height: function($calendar){
				return $(window).height() - $("h1").outerHeight();
			},
			eventRender : function(calEvent, $event) {
				if(calEvent.end.getTime() < new Date().getTime()) {
					$event.css("backgroundColor", "#aaa");
					$event.find(".time").css({"backgroundColor": "#999", "border":"1px solid #888"});
				}
			},
			eventNew : function(calEvent, $event) {
			   var endereco = '/aula_local/{{id_local}}/' + $('#calendar').weekCalendar("formatDate", calEvent.start, "Y-m-d-H-i") + '/' + $('#calendar').weekCalendar("formatDate", calEvent.end, "Y-m-d-H-i") + '/'
				$.fancybox({
				'href': endereco,
				'onComplete': function() {
										  $('#id_inicio').val($('#calendar').weekCalendar("formatDate", calEvent.start, "H:i d-m-Y"));
										  $('#id_fim').val($('#calendar').weekCalendar("formatDate", calEvent.end, "H:i d-m-Y"));
										  },
				});
				
			},
			eventAfterRender : function(calEvent, $event) {
			   $('#calendar').weekCalendar("removeUnsavedEvents")
			},
			eventClick: function(calEvent, $event){
			   var endereco2 = '/edita_aula_local/{{id_local}}/'+calEvent.id+'/'
			   $.fancybox({
			   'href': endereco2,
			   'onComplete': function() {
				  $('#id_inicio').val($('#calendar').weekCalendar("formatDate", calEvent.start, "H:i d-m-Y"));
				  $('#id_fim').val($('#calendar').weekCalendar("formatDate", calEvent.end, "H:i d-m-Y"));
				  },
			   });
			},
			draggable: function(calEvent, $event) {
			   calEvent.readOnly = true;
			},
			data:eventData
		});

		function displayMessage(message) {
			$("#message").html(message).fadeIn();
		}
		
	});



{% endblock extrahead %}

{% block content %}
	     {% if messages %}
            <ul class="messages">
        {% for message in messages %}
    <div class="notification note-{{ message.tags }}">
            <a href="#" class="close" title="Close notification">close</a>
            <p><strong>Notificação do Sistema:</strong> {{ message }}</p>
    </div>

        {% endfor %}
    </ul>
        {% endif %}
        <div class="box-header clear">
                <h2>Agenda do Local - {{local.nome}}</h2>
        </div>
	
        <div id='calendar'></div>

        

{% endblock content %}
